package com.project.poetry.service.controller;

import com.project.poetry.service.entity.dto.login.LoginUserDTO;
import com.project.poetry.service.entity.dto.login.RegUserDTO;
import com.project.poetry.service.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 登录，注册控制器
 * @author mengxj
 */
@Api("登录，注册")
@Validated
@RestController
@RequestMapping("login")
public class LoginController {

    @Resource
    private LoginService loginService;

    @ApiOperation("注册用户")
    @PostMapping("register")
    public void register(@RequestBody @Valid RegUserDTO userDTO){
        this.loginService.register(userDTO);
    }

    @ApiOperation("用户登录")
    @PostMapping("login")
    public void login(@RequestBody @Valid LoginUserDTO userDTO){
        this.loginService.login(userDTO);
    }

    @ApiOperation("注销用户")
    @GetMapping("logout")
    public void logout(){
         this.loginService.logout();
    }
 }
